package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.pojo.Homework;
import com.example.pojo.dto.HomeworkDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author GovQ
 * @description 针对表【homework】的数据库操作Mapper
 * @createDate 2024-06-18 22:13:35
 * @Entity com.example.pojo.Homework
 */
public interface HomeworkMapper extends BaseMapper<Homework> {
    @Select({
            "SELECT h.homework_id, h.homework_title, h.homework_content, h.homework_subject, h.file_url, h.file_way,",
            "h.end_date_time, h.remind_time, h.release_id, h.is_release, h.release_time, c.class_name, t.teacher_name",
            "FROM homework h",
            "JOIN classes c ON h.push_class_id = c.class_id",
            "JOIN teacher_info t ON c.head_teacher_id = t.teacher_id",
            "WHERE h.push_class_id = #{pushClassId} AND h.is_release = 1"
    })
    List<HomeworkDTO> getAllHomeworkByClassId(@Param("pushClassId") Long pushClassId);

    @Select({
            "SELECT h.homework_id, h.homework_title, h.homework_content, h.homework_subject, h.file_url, h.file_way,",
            "h.end_date_time, h.remind_time, h.release_id, h.is_release, h.release_time, c.class_name, t.teacher_name",
            "FROM homework h",
            "JOIN classes c ON h.push_class_id = c.class_id",
            "JOIN teacher_info t ON c.head_teacher_id = t.teacher_id",
            "WHERE h.release_id = #{teacherId} AND h.is_release = 1"
    })
    List<HomeworkDTO> getHomeworkByTeacherId(@Param("teacherId") Long teacherId);

    @Select({
            "SELECT h.homework_id, h.homework_title, h.homework_content, h.homework_subject, h.file_url, h.file_way,",
            "h.end_date_time, h.remind_time, h.release_id, h.is_release, h.release_time, c.class_name, t.teacher_name",
            "FROM homework h",
            "JOIN classes c ON h.push_class_id = c.class_id",
            "JOIN teacher_info t ON c.head_teacher_id = t.teacher_id",
            "WHERE h.homework_id = #{homeworkId}"
    })
    HomeworkDTO getHomeworkDetail(@Param("homeworkId") Long homeworkId);
}

